/**
 * 检查管理员是否关联了停车场
 * 若已关联则提示不允许发布，若未关联则可以发布
 */
package controller;

import hibernate.Adminstab;
import hibernate.AdminstabDAO;
import hibernate.Parkstab;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

public class ParkRegistCheck implements Action{
	private Adminstab adminstab;
	private Parkstab parkstab;
	

	public Adminstab getAdminstab() {
		return adminstab;
	}


	public void setAdminstab(Adminstab adminstab) {
		this.adminstab = adminstab;
	}


	public String execute() throws Exception {
		AdminstabDAO adminstabDAO=new AdminstabDAO();
		adminstabDAO.getSession().beginTransaction();
		try
		{
			ActionContext ctx = ActionContext.getContext();
			adminstab = (Adminstab)adminstabDAO.findByAccount(ctx.getSession().get("account")).get(0);
			parkstab = adminstab.getParkstab();

			adminstabDAO.attachDirty(adminstab);
			adminstabDAO.getSession().getTransaction().commit();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			adminstabDAO.getSession().close();
		}
		if(parkstab == null){
			return SUCCESS;
		}
		else 
			return ERROR;
	}

}
